<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Tasks After Running MyBatis Generator</title>
  <link rel="stylesheet" type="text/css" href="mbgstyle.css" />
</head>
<body>
<h1>Tasks After Running MyBatis Generator</h1>
<p>After you run MyBatis Generator (MBG), you will need to create or modify
   other MyBatis or iBATIS configuration
   artifacts.  The main tasks are as follows:</p>
<ul>
  <li>For MyBatis 3.x:
    <ul>
      <li>Create or Modify the MapperConfig.xml file</li>
    </ul>
  </li>
  <li>For iBATIS 2.x:
    <ul>
      <li>Create or Modify the SqlMapConfig.xml file</li>
      <li>Create or modify the dao.xml file (only if using the iBATIS DAO Framework)</li>
    </ul>
  </li>
</ul>

<p>Each task is described in detail below.</p>

<h2>Updating the MapperConfig.xml File (MyBatis 3.x)</h2>
<p>MyBatis 3.x uses an XML file, commonly named <code>MapperConfig.xml</code>,
to specify
information for a database connection, a transaction management scheme, and XML mapper
files that will be used in a MyBatis session.  MBG cannot create this file for you
because it knows nothing about your execution environment.  However, some of the
items in this file relate directly to MBG generated items.  Please refer to
the standard MyBatis data mapper developer guide for details about the different
configuration options.</p>

<p>MBG specific needs in the configuration file are as follows:</p>
<ul>
  <li>MBG generated XML mapper files must be listed</li>
</ul>

<p>For example, suppose that MBG has generated an XML mapper file called
<code>MyTableMapper.xml</code>, and that the file has been placed in the
<code>test.xml</code> package
of your project.  The <code>MapperConfig.xml</code> file should have these entries:</p>
<pre>
  &lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;!DOCTYPE configuration
    PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
    "http://mybatis.org/dtd/mybatis-3-config.dtd"&gt;

  &lt;configuration&gt;
    &lt;!-- Setup the transaction manager and data source that are
         appropriate for your environment
    --&gt;
    &lt;environments default"..."&gt;
      &lt;environment id"..."&gt;
        &lt;transactionManager type="..."&gt;
        &lt;/transactionManager&gt;
        &lt;dataSource type="..."&gt;
        &lt;/dataSource&gt;
      &lt;/environment&gt;
    &lt;/environments&gt;

    &lt;mappers&gt;
      &lt;!-- XML mapper files should be listed here --&gt;
      &lt;mapper resource="test/xml/MyTable_SqlMap.xml" /&gt;
    &lt;/mappers&gt;

  &lt;/configuration&gt;
</pre>

<p>If there is more than one XML mapper file (as is quite common),
then the files can be listed in any order with repeated <code>&lt;mapper&gt;</code>
elements after the <code>&lt;mappers&gt;</code> element.</p>

<p><b>Generated MapperConfig.xml</b> You may ask
MBG to generate a skeleton Mapper Configuration file with the MapperConfigPlugin.
See the <a href="configreference/plugin.html">&lt;plugin&gt;</a>
page for more information.</p>


<h2>Updating the SqlMapConfig.xml File (iBATIS 2.x)</h2>
<p>iBATIS 2 uses an XML file, commonly named <code>SqlMapConfig.xml</code>,
to specify
information for a database connection, a transaction management scheme, and SQL map XML
files that will be used in an iBATIS session.  MBG cannot create this file for you
because MBG knows nothing about your execution environment.  However, some of the
items in this file relate directly to MBG generated items.  Please refer to
the standard iBATIS data mapper developer guide for details about the different
configuration options.</p>

<p>MBG specific needs in the configuration file are as follows:</p>
<ul>
  <li>Statement namespaces must be enabled</li>
  <li>MBG generated SQL Map XML files must be listed</li>
</ul>

<p>For example, suppose that MBG has generated an SQL Map XML file called
<code>MyTable_SqlMap.xml</code>, and that the file has been placed in the
<code>test.xml</code> package
of your project.  The <code>SqlMapConfig.xml</code> file should have these entries:</p>
<pre>
  &lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;!DOCTYPE sqlMapConfig
    PUBLIC "-//ibatis.apache.org//DTD SQL Map Config 2.0//EN"
    "http://ibatis.apache.org/dtd/sql-map-config-2.dtd"&gt;

  &lt;sqlMapConfig&gt;
    &lt;!-- Statement namespaces are required for MBG --&gt;
    &lt;settings useStatementNamespaces="true" /&gt;

    &lt;!-- Setup the transaction manager and data source that are
         appropriate for your environment
    --&gt;
    &lt;transactionManager type="..."&gt;
      &lt;dataSource type="..."&gt;
      &lt;/dataSource&gt;
    &lt;/transactionManager&gt;

    &lt;!-- SQL Map XML files should be listed here --&gt;
    &lt;sqlMap resource="test/xml/MyTable_SqlMap.xml" /&gt;

  &lt;/sqlMapConfig&gt;
</pre>

<p>If there is more than one SQL Map XML file (as is quite common),
then the files can be listed in any order with repeated <code>&lt;sqlMap&gt;</code>
elements after the <code>&lt;transactionManager&gt;</code> element.</p>

<p><b>Version 1.2 New Enhancement</b> With MBG version 1.2 and later, You may ask
MBG to generate a skeleton SQL Map Configuration file with the SqlMapConfigPlugin.
See the <a href="configreference/plugin.html">&lt;plugin&gt;</a>
page for more information.</p>

<h2>Updating the dao.xml File (iBATIS 2.x)</h2>
<p><b>Important Note:</b> this step is only required if you generated DAOs for the
deprecated iBATIS DAO framework (we suggest using Spring instead).</p>
<p>The iBATIS DAO framework is configured by an xml file commonly called
<code>dao.xml</code>.  The iBATIS DAO framework uses this file to control the
database connection information for DAOs, and also to list the DAO implementation
classes and DAO interfaces.  In this file you should specify the path to your
<code>SqlMapConfig.xml</code> file, and all the MBG generated DAO interfaces
and implementation classes.</p>
<p>For example, suppose that MBG has generated a DAO interface called
<code>MyTableDAO</code> and a implementation class called
<code>MyTableDAOImpl</code>, and that the files have been placed in the
<code>test.dao</code> package
of your project.  The <code>dao.xml</code> file should have these entries:</p>


<pre>
  &lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;!DOCTYPE daoConfig
   PUBLIC "-//ibatis.apache.org//DTD DAO Configuration 2.0//EN"
   "http://ibatis.apache.org/dtd/dao-2.dtd"&gt;

  &lt;daoConfig&gt;
    &lt;context&gt;
      &lt;transactionManager type="SQLMAP"&gt;
        &lt;property name="SqlMapConfigResource"
                  value="test/SqlMapConfig.xml"/&gt;
      &lt;/transactionManager&gt;

      &lt;!-- DAO interfaces and implementations should be listed here --&gt;
      &lt;dao interface="test.dao.MyTableDAO"
           implementation="test.dao.MyTableDAOImpl" /&gt;

    &lt;/context&gt;
  &lt;/daoConfig&gt;
</pre>

</body>
</html>